package com.xiaoshuidi.cloud.module.rooms.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomSdiotWaring;
import com.xiaoshuidi.cloud.module.rooms.repository.IotWaringRepository;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomSdiotWaringService;
import com.xiaoshuidi.cloud.module.rooms.vo.RoomSdiotWaringVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 预警设置表 服务实现类
 * </p>
 *
 * @author James
 * @since 2023-05-29
 */
@Service
public class RoomSdiotWaringServiceImpl implements IRoomSdiotWaringService {
    @Autowired
    private IotWaringRepository iotWaringRepository;
    @Override
    public List<RoomSdiotWaringVo> getWaringList() {
        List<RoomSdiotWaringVo> waringVoList=new ArrayList<>();
        List<RoomSdiotWaring>list=iotWaringRepository.list();
        for(RoomSdiotWaring roomSdiotWaring : list){
            StringBuffer on=new StringBuffer();
            StringBuffer off=new StringBuffer();
            RoomSdiotWaringVo roomWaringVo=new RoomSdiotWaringVo();
            BeanUtil.copyProperties(roomSdiotWaring,roomWaringVo);
            roomWaringVo.setAmmterWaring(roomSdiotWaring.getAmmterWaring());
            roomWaringVo.setAmmterWaringDay(roomSdiotWaring.getAmmterWaringDay());
            roomWaringVo.setColdWorterWaring(roomSdiotWaring.getColdWorterWaring());
            roomWaringVo.setColdWorterWaringDay(roomSdiotWaring.getColdWorterWaringDay());
            roomWaringVo.setHotWorterWaring(roomSdiotWaring.getHotWorterWaring());
            roomWaringVo.setHotWorterWaringDay(roomSdiotWaring.getHotWorterWaringDay());
            roomWaringVo.setAmmeterPromotionWaring(roomSdiotWaring.getAmmeterPromotionWaring());
            roomWaringVo.setAmmeterPromotionWaringDay(roomSdiotWaring.getAmmeterPromotionWaringDay());
            roomWaringVo.setDoorlockPromotionWaring(roomSdiotWaring.getDoorlockPromotionWaring());
            roomWaringVo.setDoorlockPromotionWaringDay(roomSdiotWaring.getDoorlockPromotionWaringDay());
            roomWaringVo.setBz(roomSdiotWaring.getBz());
            roomWaringVo.setId(roomSdiotWaring.getId());
            if(roomSdiotWaring.getAmmeterPromotionWaring()){
                on.append("1");
            }else{
                off.append("1");
            }
            if(roomSdiotWaring.getDoorlockPromotionWaring()){
                on.append("、2");
            }else{
                off.append("、2");
            }
            if(roomSdiotWaring.getAmmterWaring()){
                on.append("、3");
            }else{
                off.append("、3");
            }
            if(roomSdiotWaring.getHotWorterWaring()){
                on.append("、4");
            }else{
                off.append("、4");
            }
            if(roomSdiotWaring.getColdWorterWaring()){
                on.append("、5");
            }else{
                off.append("、5");
            }
            if(on.length()>0) {
                on.append("开启");
            }
            if(off.length()>0){
                off.append("关闭");
            }
            if(on.length()>0&&off.length()>0){
                if(on.toString().startsWith("、")){
                    roomWaringVo.setWaringInfo(on.toString().substring(1)+","+off);
                }
                if(off.toString().startsWith("、")){
                    roomWaringVo.setWaringInfo(on+","+off.toString().substring(1));
                }
            }
            if(on.length()>0&&off.length()==0){
                roomWaringVo.setWaringInfo(on.toString());
            }
            if(off.length()>0&&on.length()==0){
                roomWaringVo.setWaringInfo(off.toString());
            }
            waringVoList.add(roomWaringVo);
        }

        return waringVoList;
    }
}
